<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class CateAscController extends Controller
{
    //menu排序
    public function menucate(Request $request)
    {
        //分类列表页
        //查询数据
        $data = DB::table('cate as c1')
        -> leftjoin('cate as c2', 'c1.pid', '=', 'c2.id') 
        -> select('c1.*','c2.name as parentName',DB::raw("CONCAT(c1.path,',',c1.id) as sortPath"))
        -> where('c1.name', 'like', '%'.$request -> input('keywords').'%' )    
        -> orderby('sortPath')
        ->paginate($request -> input('num', 20));//每页显示条数     
       
        return view('admin.cate.menucate',['data' => $data, 'request' => $request -> all()]);
        
    }

       public function navcate(Request $request)
    {
        //分类列表页
        //查询数据
        $data = DB::table('cate as c1')
        -> leftjoin('cate as c2', 'c1.pid', '=', 'c2.id') 
        -> select('c1.*','c2.name as parentName',DB::raw("CONCAT(c1.path,',',c1.id) as sortPath"))
        -> where('c1.name', 'like', '%'.$request -> input('keywords').'%' )    
        -> orderby('sortPath')
        ->paginate($request -> input('num', 20));//每页显示条数     
       
        return view('admin.cate.navcate',['data' => $data, 'request' => $request -> all()]);
        
    }

    public function navpx(Request $request)
    {
        $id = $request -> input('id');
        $data['nav_id'] = $request -> input('nav_id');
        // dd($data);
        $res = DB::table('cate') -> where('id', $id) -> update($data);
        if($res)
            {
                return response() -> json('0');
            }else
            {
                return response() -> json('5');
            }
    }

    public function menupx(Request $request)
    {
        $id = $request -> input('id');
        $data['menu_id'] = $request -> input('menu_id');
        // dd($data);
        $res = DB::table('cate') -> where('id', $id) -> update($data);
        if($res)
            {
                return response() -> json('0');
            }else
            {
                return response() -> json('5');
            }
    }
}
